// B_SpawnSoeldner wird von B_Skript_Schleife_Spawn aufgerufen, deshalb muss es vor der Funktion selbst kommen!
func void B_SpawnSoeldner (var int color)
{
    if (color == RED)
    {
        if (B_GetWayPartition(RED) < WegCounter)
        {
            PAL_1140_Soeldner.AIVAR[AIV_Weg] = 1;
        }
        else
        {
            PAL_1140_Soeldner.AIVAR[AIV_Weg] = 2;
        };
        if (Map == Varus_Map)
        {
            PAL_1140_Soeldner.AIVAR[AIV_Weg] = 2;
        };
        Wld_InsertNpc (PAL_1140_Soeldner,SpawnWaypoint);
    };
    if (color == BLUE)
    {
        if (B_GetWayPartition(BLUE) < WegCounter)
        {
            DJG_2140_Soeldner.AIVAR[AIV_Weg] = 1;
        }
        else
        {
            DJG_2140_Soeldner.AIVAR[AIV_Weg] = 2;
        };
        if (Map == Varus_Map)
        {
            DJG_2140_Soeldner.AIVAR[AIV_Weg] = 2;
        };
        Wld_InsertNpc (DJG_2140_Soeldner,SpawnWaypoint);
    };
};

func void B_SpawnSoldier_Loop()
{
	if (WegCounter == 0) { WegCounter = 1; };
	WegCounter += 1;
	
    if (WegCounter == 5) { WegCounter = 1; };
    if(NumFighter>0) { Wld_InsertNpc (PAL_1100_Soldat,SpawnWaypoint); };
    if(NumFighter>1) { Wld_InsertNpc (PAL_1100_Soldat,SpawnWaypoint); };
    if(NumFighter>2) { Wld_InsertNpc (PAL_1100_Soldat,SpawnWaypoint); };
    if(NumFighter>3) { Wld_InsertNpc (PAL_1100_Soldat,SpawnWaypoint); };
    if(NumFighter>4) { Wld_InsertNpc (PAL_1100_Soldat,SpawnWaypoint); };

	if (Map_HasTwoWays())
    {
        if (B_GetWayPartition(RED) < WegCounter)
        {
            PAL_1100_Soldat.AIVAR[AIV_Weg] = 1;
        }
        else
        {
            PAL_1100_Soldat.AIVAR[AIV_Weg] = 2;
        };
    };
    if (Map == Varus_Map)
    {
        PAL_1100_Soldat.AIVAR[AIV_Weg] = 2;
    };
    
    if(NumFighter>0) { Wld_InsertNpc (DJG_2100_Soldat,SpawnWaypoint); };
    if(NumFighter>1) { Wld_InsertNpc (DJG_2100_Soldat,SpawnWaypoint); };
    if(NumFighter>2) { Wld_InsertNpc (DJG_2100_Soldat,SpawnWaypoint); };
    if(NumFighter>3) { Wld_InsertNpc (DJG_2100_Soldat,SpawnWaypoint); };
    if(NumFighter>4) { Wld_InsertNpc (DJG_2100_Soldat,SpawnWaypoint); };

    if (Map_HasTwoWays())
    {
        if (B_GetWayPartition(BLUE) < WegCounter)
        {
            DJG_2100_Soldat.AIVAR[AIV_Weg] = 1;
        }
        else
        {
            DJG_2100_Soldat.AIVAR[AIV_Weg] = 2;
        };
    };
    if (Map == Varus_Map)
    {
        DJG_2100_Soldat.AIVAR[AIV_Weg] = 2;
    };
    
    FF_ApplyExt(B_SpawnSoldier_Loop,soldierSpawnDelay,1);
};

func void B_SpawnMage_Loop()
{
	if (B_IsMageBuilt(RED) == TRUE)
    {
        if(NumMage>0) { Wld_InsertNpc (PAL_1120_Magier,SpawnWaypoint); };
        if(NumMage>1) { Wld_InsertNpc (PAL_1120_Magier,SpawnWaypoint); };
        if(NumMage>2) { Wld_InsertNpc (PAL_1120_Magier,SpawnWaypoint); };
        if (Map_HasTwoWays())
        {
            if (B_GetWayPartition(RED) <= WegCounter)
            {
                PAL_1120_Magier.AIVAR[AIV_Weg] = 1;
            }
            else
            {
                PAL_1120_Magier.AIVAR[AIV_Weg] = 2;
            };
        };

        if (Map == Varus_Map)
        {
            PAL_1120_Magier.AIVAR[AIV_Weg] = 2;
        };
    };

    if (B_IsMageBuilt(BLUE) == TRUE)
    {
        if(NumMage>0) { Wld_InsertNpc (DJG_2120_Magier,SpawnWaypoint); };
        if(NumMage>1) { Wld_InsertNpc (DJG_2120_Magier,SpawnWaypoint); };
        if(NumMage>2) { Wld_InsertNpc (DJG_2120_Magier,SpawnWaypoint); };
        if (Map_HasTwoWays())
        {
            if (B_GetWayPartition(BLUE) <= WegCounter)
            {
                DJG_2120_Magier.AIVAR[AIV_Weg] = 1;
            }
            else
            {
                DJG_2120_Magier.AIVAR[AIV_Weg] = 2;
            };
        };
        if (Map == Varus_Map)
        {
            DJG_2120_Magier.AIVAR[AIV_Weg] = 2;
        };
    };
};

func void B_SpawnSkeleton_Loop()
{
	if (Map_HasSkeletonCave())
	{
		if (SkeletonKontroll == RED)
	    {
	        B_SetMercLevel(RED,99);
	        B_SpawnSoeldner (RED);
	    };
	    if (SkeletonKontroll == BLUE)
	    {
	        B_SetMercLevel(BLUE,99);
	        B_SpawnSoeldner (BLUE);
	    };
	};
};

func void B_SpawnManySoeldner (var int color, var int anzahl)
{
    if (Anzahl) {
        B_SpawnSoeldner (color);
        B_SpawnManySoeldner (color, anzahl-1);
    };
    return;
};
